from django.conf import settings
from django.db import models


from sqtp.models.base import BaseModel


class Project(BaseModel):
    PRO_STATUS = (
        (0, '开发中'),
        (1, '维护中'),
        (2, '稳定运行中')
    )
    admin = models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING, null=True,
                              related_name='project_admin')
    members = models.ManyToManyField(to=settings.AUTH_USER_MODEL, related_name='project_members')
    name = models.CharField(verbose_name="项目名", max_length=100, unique=True)
    status = models.CharField(verbose_name="醒目状态", max_length=32, choices=PRO_STATUS, default=1)
    version = models.CharField(verbose_name='版本', max_length=32, default='v1.0')

    class Meta:
        verbose_name = '项目表'


class Environment(BaseModel):
    SERVICE_CATEGORY = (
        (0, 'web服务器'),
        (1, '数据库服务器')
    )
    SERVICE_OS = (
        (0, 'Windows'),
        (1, 'Linux')
    )
    SERVICE_STATUS = (
        (0, 'active'),
        (1, 'disable')
    )
    project = models.ForeignKey(to=Project, on_delete=models.CASCADE, verbose_name='所属项目')
    # ip = models.GenericIPAddressField(verbose_name='ip地址', default='127.0.0.1')
    ip = models.URLField(verbose_name='服务地址', default='http://127.0.0.1')
    port = models.SmallIntegerField(verbose_name='端口号', default=80)
    category = models.SmallIntegerField(verbose_name='服务器类型', choices=SERVICE_CATEGORY, default=0)
    os = models.SmallIntegerField(verbose_name='服务器操作系统', choices=SERVICE_OS, default=0)
    status = models.SmallIntegerField(verbose_name='服务器状态', choices=SERVICE_STATUS, default=0)

    class Meta(BaseModel.Meta):
        verbose_name = '测试环境表'
